package com.toe.sso.controller;

import com.toe.common.restful.JsonResult;
import com.toe.sso.pojo.dto.AdminLoginDTO;
import com.toe.sso.pojo.dto.BusinessLoginDTO;
import com.toe.sso.pojo.vo.TokenVO;
import com.toe.sso.security.service.admin.IAdminSSOService;
import com.toe.sso.security.service.business.IBusinessSSOService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>商家管理员单点登录控制器</p>
 */
@RestController
@RequestMapping(value = "/business/sso", produces = "application/json; charset=utf-8")
@Api(tags = "商家后台管理用户认证")
@Slf4j
public class BusinessSSOController {
    @Autowired
    private IBusinessSSOService businessSSOService;
    @Value("${jwt.tokenHead}")
    private String jwtTokenHead;

    /**
     * <p>登录login</p>
     * <p>主要就是验证是否登录账号密码正确</p>
     */
    @ApiOperation(value = "后台单点登录认证登录(电话号码+密码)")
    @PostMapping("/login")
    public JsonResult<TokenVO> doLogin(@RequestBody @Validated BusinessLoginDTO businessLoginDTO){
        String token = businessSSOService.doLogin(businessLoginDTO);
        TokenVO tokenVO = new TokenVO();
        tokenVO.setTokenHeader(jwtTokenHead);
        tokenVO.setTokenValue(token);
        return JsonResult.ok(tokenVO);
    }

    @ApiOperation(value = "后台单点登录认证登录(电话号码+验证码)")
    @PostMapping("/login2")
    public JsonResult<TokenVO> doLogin2(@RequestBody @Validated BusinessLoginDTO businessLoginDTO){
        String token = businessSSOService.doLogin2(businessLoginDTO);
        TokenVO tokenVO = new TokenVO();
        tokenVO.setTokenHeader(jwtTokenHead);
        tokenVO.setTokenValue(token);
        return JsonResult.ok(tokenVO);
    }

    /**
     * <p>登出logout</p>
     * <p>没有任何实际业务逻辑</p>
     */

}
